
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuPersona.java
 *
 * Created on 24/05/2012, 04:23:51 PM
 */
package tiposgenericos;
import java.util.*;
import java.io.*;
import javax.swing.*; 

/**
 *
 * @author Miguel
 */
//TAREA 4:
public class MenuPersona extends javax.swing.JFrame {
    LinkedList listaPersonas;
    /** Creates new form MenuPersona */
    public MenuPersona() {
        initComponents();
        listaPersonas = new LinkedList();
        //List <Persona2> listaPersonas = new LinkedList<Persona2>();
    
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LblMenu = new javax.swing.JLabel();
        BtnAgregarI = new javax.swing.JButton();
        BtnAgregarF = new javax.swing.JButton();
        BtnEliminarI = new javax.swing.JButton();
        BtnEliminarF = new javax.swing.JButton();
        BtnMostrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        TxtApellidoM = new javax.swing.JTextField();
        TxtApellidoP = new javax.swing.JTextField();
        TxtNombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        TxtDireccion = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        TALista = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        LblMenu.setText("MENÚ");

        BtnAgregarI.setText("Agregar al Inicio");
        BtnAgregarI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAgregarIActionPerformed(evt);
            }
        });

        BtnAgregarF.setText("Agregar al Final");
        BtnAgregarF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAgregarFActionPerformed(evt);
            }
        });

        BtnEliminarI.setText("Eliminar al Inicio");
        BtnEliminarI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnEliminarIActionPerformed(evt);
            }
        });

        BtnEliminarF.setText("Eliminar al Final");
        BtnEliminarF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnEliminarFActionPerformed(evt);
            }
        });

        BtnMostrar.setText("Mostrar");
        BtnMostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnMostrarActionPerformed(evt);
            }
        });

        jLabel1.setText("Nombre");

        TxtNombre.setName("TxtNombre"); // NOI18N

        jLabel4.setText("Direccion:");

        jLabel2.setText("Apellido Paterno");

        jLabel3.setText("Apellido Materno");

        TALista.setColumns(20);
        TALista.setRows(5);
        jScrollPane1.setViewportView(TALista);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(256, 256, 256)
                .addComponent(LblMenu)
                .addContainerGap(252, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrar)
                            .addGap(100, 100, 100))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(TxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1))
                                    .addGap(95, 95, 95)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGap(47, 47, 47))
                                        .addComponent(TxtApellidoP, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(31, 31, 31))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(TxtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(58, 58, 58)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(TxtApellidoM, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(17, 17, 17)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(BtnEliminarI)
                                .addComponent(BtnAgregarI))
                            .addGap(39, 39, 39)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(BtnAgregarF)
                                .addComponent(BtnEliminarF))
                            .addGap(242, 242, 242)))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(LblMenu)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TxtApellidoM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(TxtApellidoP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(TxtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtnAgregarF)
                            .addComponent(BtnAgregarI))
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtnEliminarI)
                            .addComponent(BtnEliminarF)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(BtnMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void BtnAgregarFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAgregarFActionPerformed
// TODO add your handling code here:
    String Nombre = TxtNombre.getText( );
    String ApellidoP = TxtApellidoP.getText( );
    String ApellidoM = TxtApellidoM.getText( );
    String Direccion = TxtDireccion.getText( ); 
    
    Persona2 per = new Persona2(Nombre,ApellidoP,ApellidoM,Direccion);
    //Persona perso = new Persona("Juan", "15");
    
    listaPersonas.addLast(per);
    
    JOptionPane.showMessageDialog (null, "La persona se ha agregado correctamente");
    
    TxtNombre.setText(null);
    TxtApellidoP.setText(null);
    TxtApellidoM.setText(null);
    TxtDireccion.setText(null);
}//GEN-LAST:event_BtnAgregarFActionPerformed

private void BtnEliminarFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnEliminarFActionPerformed
// TODO add your handling code here:
    listaPersonas.removeLast();
    JOptionPane.showMessageDialog (null, "La persona se ha eliminado");
}//GEN-LAST:event_BtnEliminarFActionPerformed

private void BtnMostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnMostrarActionPerformed
// TODO add your handling code here:
    TALista.setText(null);
    Persona2 Per = null;
    List listaMostrar = new ArrayList(listaPersonas);
    Iterator it = listaMostrar.iterator();
    while (it.hasNext())
    {        
        Per = (Persona2) it.next();
        
        TALista.setText(TALista.getText() + Per.getNombre()+ "  " + Per.getP_Apellido()+ "  " + Per.getS_Apellido() + "  " +
        Per.getDireccion()+ "\n");
                
        //System.out.println(it.next()+"");
    }
    
}//GEN-LAST:event_BtnMostrarActionPerformed

private void BtnAgregarIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAgregarIActionPerformed
// TODO add your handling code here:
    String Nombre = TxtNombre.getText( );
    String ApellidoP = TxtApellidoP.getText( );
    String ApellidoM = TxtApellidoM.getText( );
    String Direccion = TxtDireccion.getText( ); 
    
    Persona2 per = new Persona2(Nombre,ApellidoP,ApellidoM,Direccion);
        
    listaPersonas.addFirst(per);
    
    JOptionPane.showMessageDialog (null, "La persona se ha agregado correctamente"); 
    
    TxtNombre.setText(null);
    TxtApellidoP.setText(null);
    TxtApellidoM.setText(null);
    TxtDireccion.setText(null);
}//GEN-LAST:event_BtnAgregarIActionPerformed

private void BtnEliminarIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnEliminarIActionPerformed
// TODO add your handling code here:
    listaPersonas.removeFirst();
    JOptionPane.showMessageDialog (null, "La persona se ha eliminado");
}//GEN-LAST:event_BtnEliminarIActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MenuPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MenuPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MenuPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MenuPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MenuPersona().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAgregarF;
    private javax.swing.JButton BtnAgregarI;
    private javax.swing.JButton BtnEliminarF;
    private javax.swing.JButton BtnEliminarI;
    private javax.swing.JButton BtnMostrar;
    private javax.swing.JLabel LblMenu;
    private javax.swing.JTextArea TALista;
    private javax.swing.JTextField TxtApellidoM;
    private javax.swing.JTextField TxtApellidoP;
    private javax.swing.JTextField TxtDireccion;
    private javax.swing.JTextField TxtNombre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
